package com.lse_api.exception;

import com.lse_api.utils.Status;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


/**
 * @author 祁雪
 * @Description: TODO(异常集中处理类 ， 通过Controller继承该类实现)
 * @date 2018年4月17日 下午3:54:35
 */
public class LseException {
    @ResponseBody
    @ExceptionHandler
    public Status exp(HttpServletRequest request, Exception e) {
        e.printStackTrace();
        LogFactory.getLog(super.getClass()).error(e.getMessage(), e);
        return Status.error(e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler
    public Status exp(HttpServletRequest request, NumberFormatException e) {
        e.printStackTrace();
        LogFactory.getLog(super.getClass()).error(e.getMessage(), e);
        return Status.error("Please type int", e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler
    public Status exp(HttpServletRequest request, AccessDeniedException e) {
//        LogFactory.getLog(super.getClass()).error(e.getMessage(), e);
        return Status.error(e.getMessage());
    }

}
